<?php

/**
 * Description of Routes
 *
 * @author Kelvin Pereira Alves <kelvinpalves@gmail.com>
 */
class Routes {
    private $action;
    private $method;
    
    public function redirect(){
        if(isset($_GET['c'])){
            $this->action = $_GET['c'];
        }else{
            if(isset($_POST['c'])){
                $this->action = $_POST['c'];
            }else{
                $this->action = null;
            }
        }
        
        if(isset($_GET['m'])){
            $this->method = $_GET['m'];
        }else{
            if(isset($_POST['m'])){
                $this->method = $_POST['m'];
            }else{
                $this->method = null;
            }
        }
        
        if($this->action != null){
            if($this->action == "plano"){
                $this->action = "plan";
            }
            
            $file = './Action/' . ucfirst($this->action) . 'Action.php';
            
            if(!file_exists($file)){
                $this->action = null;
            }else{
                require_once $file;
                $this->action = ucfirst($this->action) . 'Action';
            }
        }
        
        return ($this->action != null && $this->method != null);
    }
    
    function getAction() {
        return $this->action;
    }

    function getMethod() {
        return $this->method;
    }

    function setAction($action) {
        $this->action = $action;
    }

    function setMethod($method) {
        $this->method = $method;
    }
}
